<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" /> 
        <title>Weather Example: Deep Watch Version</title>
        <!-- import Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <div id="root">
            <h2>今天天气很{{info}}</h2>
            <!-- 绑定事件的时候@xx="yyy" yyy可以写一写简单的语句 -->
            <!-- <button @click="isHot = !isHot">点击切换（简写）</button> -->
            <button @click="changeWeather">点击切换</button>
            <hr/>
            <h3>a的值是{{numbers.a}}</h3>
            <button @click="numbers.a++">点我让a+1</button>
            <h3>b的值是{{numbers.b}}</h3>
            <button @click="numbers.b++">点我让b+1</button>
            <button @click="numbers = {a:666, b:999}">彻底改变</button>
        </div>
    </body>
            
    <script type="text/javascript">
        Vue.config.productionTip = false // 阻止vue在启动时生成生产提示。
        const vm = new Vue({
            el:'#root',
            data:{
                isHot: true,
                numbers: {
                    a: 1,
                    b: 2
                }
            },
            computed:{
                info(){
                    return this.isHot? "炎热" : "凉爽"
                },
                numberA(){
                    return this.numbers.a
                }
            },
            methods: {
                changeWeather(){
                    this.isHot = ! this.isHot
                }
            },
            watch:{
                // 监视多级结构中某个属性的变化
                'numbers.a':{
                    handler(newValue, oldValue){
                        console.log('number a is modified', newValue, oldValue)
                    }
                },
                // 监视多级结构中所有属性的变化
                numbers: {
                    deep: true, 
                    handler(){
                        console.log('number is modified')
                    }
                }
            }
        })
    </script>
</html>